package com.brooks.demo;

import java.util.concurrent.TimeUnit;

/**
 * @Author mihutu
 * @Date 2020/10/13 17:27
 * @Version 1.0
 */
public class DemoThreadLocal1 {
    static ThreadLocal<Person> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tl.set(new Person());
        }).start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(tl.get());
        }).start();

    }

    static class Person{
        private String name = "姓名";
    }
}
